﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Http;
using Wy.JiZhangSoft.Files;

namespace Wy.JiZhangSoft.Controllers
{
    [Route("api/file/files")]
    public class FileController : AbpController
    {
        private readonly IFileAppService _fileAppService;

        public FileController(IFileAppService fileAppService)
        {
            this._fileAppService = fileAppService;
        }

        [HttpGet]
        public async Task<FileResult> DownLoad(Guid? id)
        {           
            var dto = await _fileAppService.GetBytesAsync(id);
            return File(dto.Bytes, MimeTypes.GetByExtension(Path.GetExtension(id+"")), dto.Name);
        }
    }
}
